var i = 2; //定义密码输错的次数

//判断输入的卡号是不是数字类型
//返回true，证明不是数字；返回false，证明是数字

function checkNumber(account) {
	var pattern = /^[0-9]*[1-9][0-9]*$/;
	return pattern.test(account);
	// return isNaN(account);
}

//判断输入的卡号和密码是否为空
function checkNull(account, password) {
	if (account.length > 0 && password.length > 0) {
		return true;
	}
	return false;
}

//登录事件
function login() {
	var account = document.getElementById("account").value;
	var password = document.getElementById("password").value;

	if (!checkNull(account, password)) {
		alert("卡号和密码不能为空!");
		return; //终止登录方法，下面的代码不会执行
	}
	if (!checkNumber(account)) {
		alert("卡号必须为数字！");
		return;
	}
	if (i > 0 && account == "123456789" && password == "123") {
		window.location.href = "../index.html"
		rel = "external nofollow";
	} else {
		if (i == 0) {
			alert("当前卡号被锁定！");
			return;
		}
		alert("你还剩下" + i + "次输入卡号和密码的机会");
		i--;
		return;
	}
}

//存款
function deposit() {
	var balance = Number(document.getElementById("balance").value); //获取余额，并将其转换为数字
	var deposit = document.getElementById("deposit").value;

	if (!deposit.length > 0) {
		alert("请输入您要存款的金额");
		return;
			if(deposit%100==0){
				//满足100整数倍
				balance+=deposit;
				alert("成功存款%d,您的账户余额为：%d元",deposit,balance);
				return
			}else{
				alert("存钱金额要求是100整数倍")
				return
			}
		
	}
	if (checkNumber(deposit)) {
		alert("请输入数字");
		return;
	}

	balance += parseFloat(deposit);
	document.getElementById("balance").value = balance; //修改存款完成以后显示的余额

}

//取款
function withdraw() {
	var balance = Number(document.getElementById("balance").value); //获取余额，并将其转换为数字
	var withdraw = document.getElementById("withdraw").value;

	if (!withdraw.length > 0) {
		alert("请输入您要取款的金额");
		return;
	}
	if (checkNumber(withdraw)) {
		alert("请输入数字");
		return;
	}

	//判断取款是否大于余额
	if (parseFloat(withdraw) > balance) {
		alert("余额不足！");
	}

	balance -= parseFloat(withdraw);
	document.getElementById("balance").value = balance;
}


// 推出
function td(){
	// var balance = Number(document.getElementById("balance").value); 
	var td = document.getElementById("td")
	window.location.href = "ATM.html"

}
